package com.dailyblue.project.smbms.alibaba.stock.listener;

import com.alibaba.fastjson.JSONArray;
import com.dailyblue.project.smbms.alibaba.stock.service.StockService;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Component
@RocketMQMessageListener(topic = "Alipay", selectorExpression = "tag", consumerGroup = "alipay_group_consumer", messageModel = MessageModel.BROADCASTING)
public class StockListener implements RocketMQListener<String> {
    @Resource
    private StockService stockService;

    @Override
    public void onMessage(String s) {
        Map<String, String> map = JSONArray.parseObject(s, Map.class);
        String aid = map.get("aid");
        String order = map.get("order");
        stockService.stock(aid, order);
    }
}
